// pages/issue/issue.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        username:"",
        token:"",
        datas:[{ 
            id:0,
            username:"",
            title:"",
      
            right:"",
            type:"",
            orentation:"",
            floor:"",
            decoration:"",
            elevator:"",
            area:0,
            price:0,
            location:"",
            date:"",
            picture:"",
            other:""
           }
        ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that=this
        try {
            var value = wx.getStorageSync('username')
            var value1 = wx.getStorageSync('token')
            if (value) {
              this.setData({username:value,token:token})
            }
          } catch (e) {
            console.log("异常：从缓存获取username和token失败")
          }
          wx.request({
            url: 'http://172.23.144.125:8081/house/v1/myinfo/'+value+'/'+value1,
            method:"GET",
            success:function(res){
                if(res.data.code==200){
                    console.log("code:"+res.data.code)
                    console.log("messagef:"+res.data.message)
                    console.log("datas:"+res.data.datas)
                    that.setData({
                      datas:res.data.datas
                      
                    })
                  }
                  else{
                    console.log(res.data.message)
                    console.log("code:"+res.data.code)
                    console.log("datas:"+res.data.datas)
                  }
            }
            
          })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    Modify:function(e){
      var that=this
      var s_id=e.currentTarget.dataset.s_id
      console.log(s_id)
      try {
          var value = wx.getStorageSync('token')
          var value2 = wx.getStorageSync('username')
          if (value) {
            that.setData({token:value,username:value2})
          }
        } catch (e) {
          // Do something when catch error
          console.log("异常：获取用户token异常")
        }
        wx.showToast({
          title: '请求中',
          duration: 4000,
          icon: "loading",

        })
        wx.request({
          url: 'http://172.23.144.125:8081/house/v1/mysellinfo/'+value2+'/'+value+'/'+this.data.id,
          method:"PUT",
          success(res)
          {
              if(code==200){
                  wx.showToast({
                      title: '修改成功',
                      duration: 1000,
                      icon: "success",
                  }),
                  that.onLoad()
                  wx.switchTab({
                    url: '/pages/home/home',
                  })
              }
              else{
                  wx.showToast({
                      title: res.data.message,
                      duration: 1000,
                      icon: "error",
                  })
              }
          },
          fail(res){
              wx.showToast({
                  title: "连接超时",
                  duration: 1000,
                  icon: "error",
              }),
              that.onLoad()
          }
          
        })
    },
    Delete:function(e){
        var that=this
        var s_id=e.currentTarget.dataset.s_id
        console.log(s_id)
        try {
            var value = wx.getStorageSync('token')
            var value2 = wx.getStorageSync('username')
            if (value) {
              that.setData({token:value,username:value2})
            }
          } catch (e) {
            // Do something when catch error
            console.log("异常：获取用户token异常")
          }
          wx.showToast({
            title: '请求中',
            duration: 4000,
            icon: "loading",

          })
          wx.request({
            url: 'http://172.23.144.125:8081/house/v1/myinfo/'+value2+'/'+value+'/'+s_id,
            method:"DELETE",
            success(res)
            {
                if(res.data.code==200){
                    wx.showToast({
                        title: '删除成功',
                        duration: 1000,
                        icon: "success",
                    }),
                    that.onLoad()
                }
                else{
                    wx.showToast({
                        title: res.data.message,
                        duration: 1000,
                        icon: "error",
                    })
                }
            },
            fail(res){
                wx.showToast({
                    title: "连接超时",
                    duration: 1000,
                    icon: "error",
                }),
                that.onLoad()
            }
            
          })
    }
})